﻿from api.base_api import BaseApi


class TemplateApi(BaseApi):
    _yaml_path = "../datas/request_data/template_api.yaml"

    def get_all_system(self, env, token):
        """
        获取所有子系统
        :param env:
        :param token:
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        data = self.yaml_read(self._yaml_path, 'get_all_system')
        return self.send(data)

    def save(self, env, token, sys_code, sys_name, url, desc):
        """
        新增子系统
        :param env:
        :param token:
        :param sys_code:
        :param sys_name:
        :param url:
        :param desc:
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_code'] = sys_code
        self._params['sys_name'] = sys_name
        self._params['url'] = url
        self._params['desc'] = desc
        data = self.yaml_read(self._yaml_path, 'save')
        return self.send(data)

    def delete(self, env, token, sys_code):
        """
        删除子系统
        :param env:
        :param token:
        :param sys_code:
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_code'] = sys_code
        data = self.yaml_read(self._yaml_path, 'delete')
        return self.send(data)

    def update(self, env, token, template_id, sys_name, url, desc):
        """
        修改子系统
        :param desc: 描述
        :param url: 子系统url
        :param sys_name: 子系统名称
        :param template_id:子系统id
        :param env:环境变量
        :param token:basic-token
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['template_id'] = template_id
        self._params['sys_name'] = sys_name
        self._params['url'] = url
        self._params['desc'] = desc
        data = self.yaml_read(self._yaml_path, 'update')
        return self.send(data)

    def get_one(self, env, token, template_id):
        """
        获取一个子系统的详情
        :param env:
        :param token:
        :param template_id: 子系统id
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['template_id'] = template_id
        data = self.yaml_read(self._yaml_path, 'get_one')
        return self.send(data)

    def get_this_sys_template_corp(self, env, token, sys_code):
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_code'] = sys_code
        data = self.yaml_read(self._yaml_path, 'get_this_sys_template_corp')
        return self.send(data)

    def batch_save_corp(self, env, token, sys_code, corp_code_list):
        """
        批量应用医院(未上线，只是应用)
        :param env:环境变量
        :param token:basic-token
        :param sys_code:子系统code
        :param corp_code_list:长编号数组
        :return:
        """
        self._params['host'] = self.config_read('host', env)
        self._params['token'] = token
        self._params['sys_code'] = sys_code
        self._params['corp_code_list'] = corp_code_list
        data = self.yaml_read(self._yaml_path, 'batch_save_corp')
        return self.send(data)
